<?php

namespace App\Http\Controllers;

use App\Mail\TestMail;
use App\Mail\UserWelcome;
use App\Models\Common;
use App\Models\Setting;
use Illuminate\Http\Request;
use App\Models\Member;
use App\Models\UserInfo;
use App\Models\Role;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;

class TestController extends Controller
{

    public function index1(Request $request){

//        $user = User::find(1);
//        if($user){
//            $userinfo = $user->userinfo;
//            dd($userinfo);
//        }


//         DB::enableQueryLog();
//         //$userinfo = UserInfo::find(1);
//         //$user = $userinfo->user->email;
//         $queries = DB::getQueryLog();
//         dd($queries);


//        DB::enableQueryLog();
//        $user = User::find(1);
//        $data=[];
//        foreach ($user->role as $role) {
//            $data[] = $role['name'];
//        }
//        $queries = DB::getQueryLog();
//         dd($data);

//        $role = Role::find(3);
//        $data=[];
//        foreach ($role->permission as $permission) {
//            $data[] = $permission['name'];
//        }
//        dd($data);


        $res = $this->curl('http://v.com/api/v1/user/logout');
        dd($res);
        $request = new \Illuminate\Http\Request;
        dd($request->all());

        $dir = base_path('.env');
        $data = ['APP_ADMIN_NAME'=>'sss'];
        Setting::modifyEnv($data);
        //$dir = base_path('app/Http');
        dd('ss');
        $file=scandir($dir);
        //$handler = opendir($res);
        //$envPath = base_path('.env');
        //$res = file($envPath);
        dd($file);
	}

    public function index(Request $request)
    {
//        $value = config('database.connections.mysql.prefix');
//        dd($value);
        $arr = [
          ['key'=>'zz','value'=>'xx'],
        ];
        Common::updateBatch('setting',$arr);
        dd('zzz');
        global $_G;
        $avatar = $request->file('avatar');
        $avatarpath = $this->uploadFile($avatar,'/avatar');
        if($avatarpath){
            $user = User::find(1);
            $user->avatar = $avatarpath;
            if($user->save()){
                return $this->resJson(['code'=>701,'data'=>$_G['siteurl'].$avatarpath,'msg'=>'格式不支持']);
            }
        }
        return $this->resJson(['code'=>702,'data'=>'','msg'=>'上传失败']);
    }

    public function mail()
    {
        $res['subject']='欢迎注册';
        $res['username']='xx';
        $res['email']='121099327@qq.com';
        Mail::to('121099327@qq.com')->send(new UserWelcome($res));

//        $text= '我想说的是我挺喜欢的';
//        Mail::raw($text,function ($message){
//            $message->subject('关于求学');
//            $message->to('121099327@qq.com');
//        });
    }

}
